package com.hhkj.api.order.model.res;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hhkj.admin.order.model.dopo.OrderPo;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;

/**
 * ApiOrderRes
 *
 * @author zheng
 * @since 2023/11/2 22:01
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class ApiOrderRes extends OrderPo {

    /** 是否距离支付时间再24小时之内：1-在24小时之内 0-超过24小时 **/
    private Integer in24Hours;

    public Integer getIn24Hours() {
        Date payTime = getPayTime();
        if (ObjectUtil.isEmpty(payTime)) {
            return 0;
        }
        DateTime dateTime = DateUtil.offsetDay(payTime, 1);
        if (dateTime.compareTo(new Date()) > 0) {
            return 1;
        }
        return 0;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    @JsonIgnore(value = false)
    @Override
    public Date getCreateTime() {
        return super.getCreateTime();
    }
}
